<template>
  <div>
    <el-container class="home-container" style="height: 500px; border: 1px solid #eee">
      <el-header>
        <span>用户权限管理系统</span>

        <!-- <a @click="logout" class="quit">安全退出</a> -->
        <div>
          <span id="uname">{{uname}}</span>
          <el-button type="danger" round @click="logout">退出</el-button>
        </div>
      </el-header>
      <el-container class="chight">
        <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
          <el-menu
            default-active="/home/welcome"
            :router="true"
          >
            <el-menu-item index="/home/welcome">
              <i class="el-icon-location"></i>
              <span slot="title">首页</span>
            </el-menu-item>
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-setting"></i>系统管理
              </template>
              <el-menu-item v-for="(item,i) in navbar" :key="i" :index="item.navPath">
                <template slot="title">
                  <i :class="item.navClass"></i>
                  <span>{{item.navItem}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <router-view></router-view>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Cantain",
  data() {
    return {
      uname: "",
      navbar: [
        {
          navItem: "用户管理",
          navPath: "/home/userList",
          navClass: "el-icon-user"
        }
      ]
    };
  },
  methods: {
    logout() {
      // localStorage.setItem("Name", "");
      localStorage.removeItem("Name");
      localStorage.clear();
      this.$router.push({ path: "/login" });
    }
  },
  mounted: function() {
    this.uname = localStorage.getItem("Name");
    const that=this;
    this.$http
        .get("/findAll")
        .then(function(response) {
          // console.log(response.data);
          that.navbar = response.data;;
        })
        .catch(function(error) {
          console.log(error);
        });
  }
};
</script>

<style>
.el-header {
  background-color: #303133c2;
  color: #333;
  line-height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
}

.el-aside {
  color: #333;
}
.home-container {
  height: 100%;
}
#uname {
  margin-right: 20px;
}

</style>